home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / flex_2_3 / part04 < prev    next >
Encoding:
Internet Message Format  |  1990-08-19  |  49.0 KB

  1. Path: abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v90i231: flex 2.3 - fast lexical analyzer generator, Part04/13
  4. Reply-To: loftus@wpllabs.uucp (William P Loftus)
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v90i231@abcfd20.larc.nasa.gov>
  7. Date: 19 Aug 90 22:42:25 GMT
  8. Approved: tadguy@uunet.UU.NET (Tad Guy)
  9. X-Mail-Submissions-To: amiga@uunet.uu.net
  10. X-Post-Discussions-To: comp.sys.amiga
  11.  
  12. Submitted-by: loftus@wpllabs.uucp (William P Loftus)
  13. Posting-number: Volume 90, Issue 231
  14. Archive-name: unix/flex-2.3/part04
  15.  
  16. #!/bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 4 (of 13)."
  23. # Contents:  flex.1 tblcmp.c
  24. # Wrapped by tadguy@abcfd20 on Sun Aug 19 18:41:43 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'flex.1' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'flex.1'\"
  28. else
  29. echo shar: Extracting \"'flex.1'\" \(20799 characters\)
  30. sed "s/^X//" >'flex.1' <<'END_OF_FILE'
  31. X.TH FLEX 1 "26 May 1990" "Version 2.3"
  32. X.SH NAME
  33. Xflex - fast lexical analyzer generator
  34. X.SH SYNOPSIS
  35. X.B flex
  36. X.B [-bcdfinpstvFILT8 -C[efmF] -Sskeleton]
  37. X.I [filename ...]
  38. X.SH DESCRIPTION
  39. X.I flex
  40. Xis a tool for generating
  41. X.I scanners:
  42. Xprograms which recognized lexical patterns in text.
  43. X.I flex
  44. Xreads
  45. Xthe given input files, or its standard input if no file names are given,
  46. Xfor a description of a scanner to generate.  The description is in
  47. Xthe form of pairs
  48. Xof regular expressions and C code, called
  49. X.I rules.  flex
  50. Xgenerates as output a C source file,
  51. X.B lex.yy.c,
  52. Xwhich defines a routine
  53. X.B yylex().
  54. XThis file is compiled and linked with the
  55. X.B -lfl
  56. Xlibrary to produce an executable.  When the executable is run,
  57. Xit analyzes its input for occurrences
  58. Xof the regular expressions.  Whenever it finds one, it executes
  59. Xthe corresponding C code.
  60. X.LP
  61. XFor full documentation, see
  62. X.B flexdoc(1).
  63. XThis manual entry is intended for use as a quick reference.
  64. X.SH OPTIONS
  65. X.I flex
  66. Xhas the following options:
  67. X.TP
  68. X.B -b
  69. XGenerate backtracking information to
  70. X.I lex.backtrack.
  71. XThis is a list of scanner states which require backtracking
  72. Xand the input characters on which they do so.  By adding rules one
  73. Xcan remove backtracking states.  If all backtracking states
  74. Xare eliminated and
  75. X.B -f
  76. Xor
  77. X.B -F
  78. Xis used, the generated scanner will run faster.
  79. X.TP
  80. X.B -c
  81. Xis a do-nothing, deprecated option included for POSIX compliance.
  82. X.IP
  83. X.B NOTE:
  84. Xin previous releases of
  85. X.I flex
  86. X.B -c
  87. Xspecified table-compression options.  This functionality is
  88. Xnow given by the
  89. X.B -C
  90. Xflag.  To ease the the impact of this change, when
  91. X.I flex
  92. Xencounters
  93. X.B -c,
  94. Xit currently issues a warning message and assumes that
  95. X.B -C
  96. Xwas desired instead.  In the future this "promotion" of
  97. X.B -c
  98. Xto
  99. X.B -C
  100. Xwill go away in the name of full POSIX compliance (unless
  101. Xthe POSIX meaning is removed first).
  102. X.TP
  103. X.B -d
  104. Xmakes the generated scanner run in
  105. X.I debug
  106. Xmode.  Whenever a pattern is recognized and the global
  107. X.B yy_flex_debug
  108. Xis non-zero (which is the default), the scanner will
  109. Xwrite to
  110. X.I stderr
  111. Xa line of the form:
  112. X.nf
  113. X
  114. X    --accepting rule at line 53 ("the matched text")
  115. X
  116. X.fi
  117. XThe line number refers to the location of the rule in the file
  118. Xdefining the scanner (i.e., the file that was fed to flex).  Messages
  119. Xare also generated when the scanner backtracks, accepts the
  120. Xdefault rule, reaches the end of its input buffer (or encounters
  121. Xa NUL; the two look the same as far as the scanner's concerned),
  122. Xor reaches an end-of-file.
  123. X.TP
  124. X.B -f
  125. Xspecifies (take your pick)
  126. X.I full table
  127. Xor
  128. X.I fast scanner.
  129. XNo table compression is done.  The result is large but fast.
  130. XThis option is equivalent to
  131. X.B -Cf
  132. X(see below).
  133. X.TP
  134. X.B -i
  135. Xinstructs
  136. X.I flex
  137. Xto generate a
  138. X.I case-insensitive
  139. Xscanner.  The case of letters given in the
  140. X.I flex
  141. Xinput patterns will
  142. Xbe ignored, and tokens in the input will be matched regardless of case.  The
  143. Xmatched text given in
  144. X.I yytext
  145. Xwill have the preserved case (i.e., it will not be folded).
  146. X.TP
  147. X.B -n
  148. Xis another do-nothing, deprecated option included only for
  149. XPOSIX compliance.
  150. X.TP
  151. X.B -p
  152. Xgenerates a performance report to stderr.  The report
  153. Xconsists of comments regarding features of the
  154. X.I flex
  155. Xinput file which will cause a loss of performance in the resulting scanner.
  156. X.TP
  157. X.B -s
  158. Xcauses the
  159. X.I default rule
  160. X(that unmatched scanner input is echoed to
  161. X.I stdout)
  162. Xto be suppressed.  If the scanner encounters input that does not
  163. Xmatch any of its rules, it aborts with an error.
  164. X.TP
  165. X.B -t
  166. Xinstructs
  167. X.I flex
  168. Xto write the scanner it generates to standard output instead
  169. Xof
  170. X.B lex.yy.c.
  171. X.TP
  172. X.B -v
  173. Xspecifies that
  174. X.I flex
  175. Xshould write to
  176. X.I stderr
  177. Xa summary of statistics regarding the scanner it generates.
  178. X.TP
  179. X.B -F
  180. Xspecifies that the
  181. X.ul
  182. Xfast
  183. Xscanner table representation should be used.  This representation is
  184. Xabout as fast as the full table representation
  185. X.ul
  186. X(-f),
  187. Xand for some sets of patterns will be considerably smaller (and for
  188. Xothers, larger).  See
  189. X.B flexdoc(1)
  190. Xfor details.
  191. X.IP
  192. XThis option is equivalent to
  193. X.B -CF
  194. X(see below).
  195. X.TP
  196. X.B -I
  197. Xinstructs
  198. X.I flex
  199. Xto generate an
  200. X.I interactive
  201. Xscanner, that is, a scanner which stops immediately rather than
  202. Xlooking ahead if it knows
  203. Xthat the currently scanned text cannot be part of a longer rule's match.
  204. XAgain, see
  205. X.B flexdoc(1)
  206. Xfor details.
  207. X.IP
  208. XNote,
  209. X.B -I
  210. Xcannot be used in conjunction with
  211. X.I full
  212. Xor
  213. X.I fast tables,
  214. Xi.e., the
  215. X.B -f, -F, -Cf,
  216. Xor
  217. X.B -CF
  218. Xflags.
  219. X.TP
  220. X.B -L
  221. Xinstructs
  222. X.I flex
  223. Xnot to generate
  224. X.B #line
  225. Xdirectives in
  226. X.B lex.yy.c.
  227. XThe default is to generate such directives so error
  228. Xmessages in the actions will be correctly
  229. Xlocated with respect to the original
  230. X.I flex
  231. Xinput file, and not to
  232. Xthe fairly meaningless line numbers of
  233. X.B lex.yy.c.
  234. X.TP
  235. X.B -T
  236. Xmakes
  237. X.I flex
  238. Xrun in
  239. X.I trace
  240. Xmode.  It will generate a lot of messages to
  241. X.I stdout
  242. Xconcerning
  243. Xthe form of the input and the resultant non-deterministic and deterministic
  244. Xfinite automata.  This option is mostly for use in maintaining
  245. X.I flex.
  246. X.TP
  247. X.B -8
  248. Xinstructs
  249. X.I flex
  250. Xto generate an 8-bit scanner.
  251. XOn some sites, this is the default.  On others, the default
  252. Xis 7-bit characters.  To see which is the case, check the verbose
  253. X.B (-v)
  254. Xoutput for "equivalence classes created".  If the denominator of
  255. Xthe number shown is 128, then by default
  256. X.I flex
  257. Xis generating 7-bit characters.  If it is 256, then the default is
  258. X8-bit characters.
  259. X.TP 
  260. X.B -C[efmF]
  261. Xcontrols the degree of table compression.
  262. X.IP
  263. X.B -Ce
  264. Xdirects
  265. X.I flex
  266. Xto construct
  267. X.I equivalence classes,
  268. Xi.e., sets of characters
  269. Xwhich have identical lexical properties.
  270. XEquivalence classes usually give
  271. Xdramatic reductions in the final table/object file sizes (typically
  272. Xa factor of 2-5) and are pretty cheap performance-wise (one array
  273. Xlook-up per character scanned).
  274. X.IP
  275. X.B -Cf
  276. Xspecifies that the
  277. X.I full
  278. Xscanner tables should be generated -
  279. X.I flex
  280. Xshould not compress the
  281. Xtables by taking advantages of similar transition functions for
  282. Xdifferent states.
  283. X.IP
  284. X.B -CF
  285. Xspecifies that the alternate fast scanner representation (described in
  286. X.B flexdoc(1))
  287. Xshould be used.
  288. X.IP
  289. X.B -Cm
  290. Xdirects
  291. X.I flex
  292. Xto construct
  293. X.I meta-equivalence classes,
  294. Xwhich are sets of equivalence classes (or characters, if equivalence
  295. Xclasses are not being used) that are commonly used together.  Meta-equivalence
  296. Xclasses are often a big win when using compressed tables, but they
  297. Xhave a moderate performance impact (one or two "if" tests and one
  298. Xarray look-up per character scanned).
  299. X.IP
  300. XA lone
  301. X.B -C
  302. Xspecifies that the scanner tables should be compressed but neither
  303. Xequivalence classes nor meta-equivalence classes should be used.
  304. X.IP
  305. XThe options
  306. X.B -Cf
  307. Xor
  308. X.B -CF
  309. Xand
  310. X.B -Cm
  311. Xdo not make sense together - there is no opportunity for meta-equivalence
  312. Xclasses if the table is not being compressed.  Otherwise the options
  313. Xmay be freely mixed.
  314. X.IP
  315. XThe default setting is
  316. X.B -Cem,
  317. Xwhich specifies that
  318. X.I flex
  319. Xshould generate equivalence classes
  320. Xand meta-equivalence classes.  This setting provides the highest
  321. Xdegree of table compression.  You can trade off
  322. Xfaster-executing scanners at the cost of larger tables with
  323. Xthe following generally being true:
  324. X.nf
  325. X
  326. X    slowest & smallest
  327. X          -Cem
  328. X          -Cm
  329. X          -Ce
  330. X          -C
  331. X          -C{f,F}e
  332. X          -C{f,F}
  333. X    fastest & largest
  334. X
  335. X.fi
  336. X.IP
  337. X.B -C
  338. Xoptions are not cumulative; whenever the flag is encountered, the
  339. Xprevious -C settings are forgotten.
  340. X.TP
  341. X.B -Sskeleton_file
  342. Xoverrides the default skeleton file from which
  343. X.I flex
  344. Xconstructs its scanners.  You'll never need this option unless you are doing
  345. X.I flex
  346. Xmaintenance or development.
  347. X.SH SUMMARY OF FLEX REGULAR EXPRESSIONS
  348. XThe patterns in the input are written using an extended set of regular
  349. Xexpressions.  These are:
  350. X.nf
  351. X
  352. X    x          match the character 'x'
  353. X    .          any character except newline
  354. X    [xyz]      a "character class"; in this case, the pattern
  355. X                 matches either an 'x', a 'y', or a 'z'
  356. X    [abj-oZ]   a "character class" with a range in it; matches
  357. X                 an 'a', a 'b', any letter from 'j' through 'o',
  358. X                 or a 'Z'
  359. X    [^A-Z]     a "negated character class", i.e., any character
  360. X                 but those in the class.  In this case, any
  361. X                 character EXCEPT an uppercase letter.
  362. X    [^A-Z\\n]   any character EXCEPT an uppercase letter or
  363. X                 a newline
  364. X    r*         zero or more r's, where r is any regular expression
  365. X    r+         one or more r's
  366. X    r?         zero or one r's (that is, "an optional r")
  367. X    r{2,5}     anywhere from two to five r's
  368. X    r{2,}      two or more r's
  369. X    r{4}       exactly 4 r's
  370. X    {name}     the expansion of the "name" definition
  371. X               (see above)
  372. X    "[xyz]\\"foo"
  373. X               the literal string: [xyz]"foo
  374. X    \\X         if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
  375. X                 then the ANSI-C interpretation of \\x.
  376. X                 Otherwise, a literal 'X' (used to escape
  377. X                 operators such as '*')
  378. X    \\123       the character with octal value 123
  379. X    \\x2a       the character with hexadecimal value 2a
  380. X    (r)        match an r; parentheses are used to override
  381. X                 precedence (see below)
  382. X
  383. X
  384. X    rs         the regular expression r followed by the
  385. X                 regular expression s; called "concatenation"
  386. X
  387. X
  388. X    r|s        either an r or an s
  389. X
  390. X
  391. X    r/s        an r but only if it is followed by an s.  The
  392. X                 s is not part of the matched text.  This type
  393. X                 of pattern is called as "trailing context".
  394. X    ^r         an r, but only at the beginning of a line
  395. X    r$         an r, but only at the end of a line.  Equivalent
  396. X                 to "r/\\n".
  397. X
  398. X
  399. X    <s>r       an r, but only in start condition s (see
  400. X               below for discussion of start conditions)
  401. X    <s1,s2,s3>r
  402. X               same, but in any of start conditions s1,
  403. X               s2, or s3
  404. X
  405. X
  406. X    <<EOF>>    an end-of-file
  407. X    <s1,s2><<EOF>>
  408. X               an end-of-file when in start condition s1 or s2
  409. X
  410. X.fi
  411. XThe regular expressions listed above are grouped according to
  412. Xprecedence, from highest precedence at the top to lowest at the bottom.
  413. XThose grouped together have equal precedence.
  414. X.LP
  415. XSome notes on patterns:
  416. X.IP -
  417. XNegated character classes
  418. X.I match newlines
  419. Xunless "\\n" (or an equivalent escape sequence) is one of the
  420. Xcharacters explicitly present in the negated character class
  421. X(e.g., "[^A-Z\\n]").
  422. X.IP -
  423. XA rule can have at most one instance of trailing context (the '/' operator
  424. Xor the '$' operator).  The start condition, '^', and "<<EOF>>" patterns
  425. Xcan only occur at the beginning of a pattern, and, as well as with '/' and '$',
  426. Xcannot be grouped inside parentheses.  The following are all illegal:
  427. X.nf
  428. X
  429. X    foo/bar$
  430. X    foo|(bar$)
  431. X    foo|^bar
  432. X    <sc1>foo<sc2>bar
  433. X
  434. X.fi
  435. X.SH SUMMARY OF SPECIAL ACTIONS
  436. XIn addition to arbitrary C code, the following can appear in actions:
  437. X.IP -
  438. X.B ECHO
  439. Xcopies yytext to the scanner's output.
  440. X.IP -
  441. X.B BEGIN
  442. Xfollowed by the name of a start condition places the scanner in the
  443. Xcorresponding start condition.
  444. X.IP -
  445. X.B REJECT
  446. Xdirects the scanner to proceed on to the "second best" rule which matched the
  447. Xinput (or a prefix of the input).
  448. X.B yytext
  449. Xand
  450. X.B yyleng
  451. Xare set up appropriately.  Note that
  452. X.B REJECT
  453. Xis a particularly expensive feature in terms scanner performance;
  454. Xif it is used in
  455. X.I any
  456. Xof the scanner's actions it will slow down
  457. X.I all
  458. Xof the scanner's matching.  Furthermore,
  459. X.B REJECT
  460. Xcannot be used with the
  461. X.I -f
  462. Xor
  463. X.I -F
  464. Xoptions.
  465. X.IP
  466. XNote also that unlike the other special actions,
  467. X.B REJECT
  468. Xis a
  469. X.I branch;
  470. Xcode immediately following it in the action will
  471. X.I not
  472. Xbe executed.
  473. X.IP -
  474. X.B yymore()
  475. Xtells the scanner that the next time it matches a rule, the corresponding
  476. Xtoken should be
  477. X.I appended
  478. Xonto the current value of
  479. X.B yytext
  480. Xrather than replacing it.
  481. X.IP -
  482. X.B yyless(n)
  483. Xreturns all but the first
  484. X.I n
  485. Xcharacters of the current token back to the input stream, where they
  486. Xwill be rescanned when the scanner looks for the next match.
  487. X.B yytext
  488. Xand
  489. X.B yyleng
  490. Xare adjusted appropriately (e.g.,
  491. X.B yyleng
  492. Xwill now be equal to
  493. X.I n
  494. X).
  495. X.IP -
  496. X.B unput(c)
  497. Xputs the character
  498. X.I c
  499. Xback onto the input stream.  It will be the next character scanned.
  500. X.IP -
  501. X.B input()
  502. Xreads the next character from the input stream (this routine is called
  503. X.B yyinput()
  504. Xif the scanner is compiled using
  505. X.B C++).
  506. X.IP -
  507. X.B yyterminate()
  508. Xcan be used in lieu of a return statement in an action.  It terminates
  509. Xthe scanner and returns a 0 to the scanner's caller, indicating "all done".
  510. X.IP
  511. XBy default,
  512. X.B yyterminate()
  513. Xis also called when an end-of-file is encountered.  It is a macro and
  514. Xmay be redefined.
  515. X.IP -
  516. X.B YY_NEW_FILE
  517. Xis an action available only in <<EOF>> rules.  It means "Okay, I've
  518. Xset up a new input file, continue scanning".
  519. X.IP -
  520. X.B yy_create_buffer( file, size )
  521. Xtakes a
  522. X.I FILE
  523. Xpointer and an integer
  524. X.I size.
  525. XIt returns a YY_BUFFER_STATE
  526. Xhandle to a new input buffer large enough to accomodate
  527. X.I size
  528. Xcharacters and associated with the given file.  When in doubt, use
  529. X.B YY_BUF_SIZE
  530. Xfor the size.
  531. X.IP -
  532. X.B yy_switch_to_buffer( new_buffer )
  533. Xswitches the scanner's processing to scan for tokens from
  534. Xthe given buffer, which must be a YY_BUFFER_STATE.
  535. X.IP -
  536. X.B yy_delete_buffer( buffer )
  537. Xdeletes the given buffer.
  538. X.SH VALUES AVAILABLE TO THE USER
  539. X.IP -
  540. X.B char *yytext
  541. Xholds the text of the current token.  It may not be modified.
  542. X.IP -
  543. X.B int yyleng
  544. Xholds the length of the current token.  It may not be modified.
  545. X.IP -
  546. X.B FILE *yyin
  547. Xis the file which by default
  548. X.I flex
  549. Xreads from.  It may be redefined but doing so only makes sense before
  550. Xscanning begins.  Changing it in the middle of scanning will have
  551. Xunexpected results since
  552. X.I flex
  553. Xbuffers its input.  Once scanning terminates because an end-of-file
  554. Xhas been seen,
  555. X.B
  556. Xvoid yyrestart( FILE *new_file )
  557. Xmay be called to point
  558. X.I yyin
  559. Xat the new input file.
  560. X.IP -
  561. X.B FILE *yyout
  562. Xis the file to which
  563. X.B ECHO
  564. Xactions are done.  It can be reassigned by the user.
  565. X.IP -
  566. X.B YY_CURRENT_BUFFER
  567. Xreturns a
  568. X.B YY_BUFFER_STATE
  569. Xhandle to the current buffer.
  570. X.SH MACROS THE USER CAN REDEFINE
  571. X.IP -
  572. X.B YY_DECL
  573. Xcontrols how the scanning routine is declared.
  574. XBy default, it is "int yylex()", or, if prototypes are being
  575. Xused, "int yylex(void)".  This definition may be changed by redefining
  576. Xthe "YY_DECL" macro.  Note that
  577. Xif you give arguments to the scanning routine using a
  578. XK&R-style/non-prototyped function declaration, you must terminate
  579. Xthe definition with a semi-colon (;).
  580. X.IP -
  581. XThe nature of how the scanner
  582. Xgets its input can be controlled by redefining the
  583. X.B YY_INPUT
  584. Xmacro.
  585. XYY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)".  Its
  586. Xaction is to place up to
  587. X.I max_size
  588. Xcharacters in the character array
  589. X.I buf
  590. Xand return in the integer variable
  591. X.I result
  592. Xeither the
  593. Xnumber of characters read or the constant YY_NULL (0 on Unix systems)
  594. Xto indicate EOF.  The default YY_INPUT reads from the
  595. Xglobal file-pointer "yyin".
  596. XA sample redefinition of YY_INPUT (in the definitions
  597. Xsection of the input file):
  598. X.nf
  599. X
  600. X    %{
  601. X    #undef YY_INPUT
  602. X    #define YY_INPUT(buf,result,max_size) \\
  603. X        { \\
  604. X        int c = getchar(); \\
  605. X        result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\
  606. X        }
  607. X    %}
  608. X
  609. X.fi
  610. X.IP -
  611. XWhen the scanner receives an end-of-file indication from YY_INPUT,
  612. Xit then checks the
  613. X.B yywrap()
  614. Xfunction.  If
  615. X.B yywrap()
  616. Xreturns false (zero), then it is assumed that the
  617. Xfunction has gone ahead and set up
  618. X.I yyin
  619. Xto point to another input file, and scanning continues.  If it returns
  620. Xtrue (non-zero), then the scanner terminates, returning 0 to its
  621. Xcaller.
  622. X.IP
  623. XThe default
  624. X.B yywrap()
  625. Xalways returns 1.  Presently, to redefine it you must first
  626. X"#undef yywrap", as it is currently implemented as a macro.  It is
  627. Xlikely that
  628. X.B yywrap()
  629. Xwill soon be defined to be a function rather than a macro.
  630. X.IP -
  631. XYY_USER_ACTION
  632. Xcan be redefined to provide an action
  633. Xwhich is always executed prior to the matched rule's action.
  634. X.IP -
  635. XThe macro
  636. X.B YY_USER_INIT
  637. Xmay be redefined to provide an action which is always executed before
  638. Xthe first scan.
  639. X.IP -
  640. XIn the generated scanner, the actions are all gathered in one large
  641. Xswitch statement and separated using
  642. X.B YY_BREAK,
  643. Xwhich may be redefined.  By default, it is simply a "break", to separate
  644. Xeach rule's action from the following rule's.
  645. X.SH FILES
  646. X.TP
  647. X.I flex.skel
  648. Xskeleton scanner.
  649. X.TP
  650. X.I lex.yy.c
  651. Xgenerated scanner (called
  652. X.I lexyy.c
  653. Xon some systems).
  654. X.TP
  655. X.I lex.backtrack
  656. Xbacktracking information for
  657. X.B -b
  658. Xflag (called
  659. X.I lex.bck
  660. Xon some systems).
  661. X.TP
  662. X.B -lfl
  663. Xlibrary with which to link the scanners.
  664. X.SH "SEE ALSO"
  665. X.LP
  666. Xflexdoc(1), lex(1), yacc(1), sed(1), awk(1).
  667. X.LP
  668. XM. E. Lesk and E. Schmidt,
  669. X.I LEX - Lexical Analyzer Generator
  670. X.SH DIAGNOSTICS
  671. X.I reject_used_but_not_detected undefined
  672. Xor
  673. X.LP
  674. X.I yymore_used_but_not_detected undefined -
  675. XThese errors can occur at compile time.  They indicate that the
  676. Xscanner uses
  677. X.B REJECT
  678. Xor
  679. X.B yymore()
  680. Xbut that
  681. X.I flex
  682. Xfailed to notice the fact, meaning that
  683. X.I flex
  684. Xscanned the first two sections looking for occurrences of these actions
  685. Xand failed to find any, but somehow you snuck some in (via a #include
  686. Xfile, for example).  Make an explicit reference to the action in your
  687. X.I flex
  688. Xinput file.  (Note that previously
  689. X.I flex
  690. Xsupported a
  691. X.B %used/%unused
  692. Xmechanism for dealing with this problem; this feature is still supported
  693. Xbut now deprecated, and will go away soon unless the author hears from
  694. Xpeople who can argue compellingly that they need it.)
  695. X.LP
  696. X.I flex scanner jammed -
  697. Xa scanner compiled with
  698. X.B -s
  699. Xhas encountered an input string which wasn't matched by
  700. Xany of its rules.
  701. X.LP
  702. X.I flex input buffer overflowed -
  703. Xa scanner rule matched a string long enough to overflow the
  704. Xscanner's internal input buffer (16K bytes - controlled by
  705. X.B YY_BUF_MAX
  706. Xin "flex.skel").
  707. X.LP
  708. X.I scanner requires -8 flag -
  709. XYour scanner specification includes recognizing 8-bit characters and
  710. Xyou did not specify the -8 flag (and your site has not installed flex
  711. Xwith -8 as the default).
  712. X.LP
  713. X.I
  714. Xfatal flex scanner internal error--end of buffer missed -
  715. XThis can occur in an scanner which is reentered after a long-jump
  716. Xhas jumped out (or over) the scanner's activation frame.  Before
  717. Xreentering the scanner, use:
  718. X.nf
  719. X
  720. X    yyrestart( yyin );
  721. X
  722. X.fi
  723. X.LP
  724. X.I too many %t classes! -
  725. XYou managed to put every single character into its own %t class.
  726. X.I flex
  727. Xrequires that at least one of the classes share characters.
  728. X.SH AUTHOR
  729. XVern Paxson, with the help of many ideas and much inspiration from
  730. XVan Jacobson.  Original version by Jef Poskanzer.
  731. X.LP
  732. XSee flexdoc(1) for additional credits and the address to send comments to.
  733. X.SH DEFICIENCIES / BUGS
  734. X.LP
  735. XSome trailing context
  736. Xpatterns cannot be properly matched and generate
  737. Xwarning messages ("Dangerous trailing context").  These are
  738. Xpatterns where the ending of the
  739. Xfirst part of the rule matches the beginning of the second
  740. Xpart, such as "zx*/xy*", where the 'x*' matches the 'x' at
  741. Xthe beginning of the trailing context.  (Note that the POSIX draft
  742. Xstates that the text matched by such patterns is undefined.)
  743. X.LP
  744. XFor some trailing context rules, parts which are actually fixed-length are
  745. Xnot recognized as such, leading to the abovementioned performance loss.
  746. XIn particular, parts using '|' or {n} (such as "foo{3}") are always
  747. Xconsidered variable-length.
  748. X.LP
  749. XCombining trailing context with the special '|' action can result in
  750. X.I fixed
  751. Xtrailing context being turned into the more expensive
  752. X.I variable
  753. Xtrailing context.  For example, this happens in the following example:
  754. X.nf
  755. X
  756. X    %%
  757. X    abc      |
  758. X    xyz/def
  759. X
  760. X.fi
  761. X.LP
  762. XUse of unput() invalidates yytext and yyleng.
  763. X.LP
  764. XUse of unput() to push back more text than was matched can
  765. Xresult in the pushed-back text matching a beginning-of-line ('^')
  766. Xrule even though it didn't come at the beginning of the line
  767. X(though this is rare!).
  768. X.LP
  769. XPattern-matching of NUL's is substantially slower than matching other
  770. Xcharacters.
  771. X.LP
  772. X.I flex
  773. Xdoes not generate correct #line directives for code internal
  774. Xto the scanner; thus, bugs in
  775. X.I flex.skel
  776. Xyield bogus line numbers.
  777. X.LP
  778. XDue to both buffering of input and read-ahead, you cannot intermix
  779. Xcalls to <stdio.h> routines, such as, for example,
  780. X.B getchar(),
  781. Xwith
  782. X.I flex
  783. Xrules and expect it to work.  Call
  784. X.B input()
  785. Xinstead.
  786. X.LP
  787. XThe total table entries listed by the
  788. X.B -v
  789. Xflag excludes the number of table entries needed to determine
  790. Xwhat rule has been matched.  The number of entries is equal
  791. Xto the number of DFA states if the scanner does not use
  792. X.B REJECT,
  793. Xand somewhat greater than the number of states if it does.
  794. X.LP
  795. X.B REJECT
  796. Xcannot be used with the
  797. X.I -f
  798. Xor
  799. X.I -F
  800. Xoptions.
  801. X.LP
  802. XSome of the macros, such as
  803. X.B yywrap(),
  804. Xmay in the future become functions which live in the
  805. X.B -lfl
  806. Xlibrary.  This will doubtless break a lot of code, but may be
  807. Xrequired for POSIX-compliance.
  808. X.LP
  809. XThe
  810. X.I flex
  811. Xinternal algorithms need documentation.
  812. END_OF_FILE
  813. if test 20799 -ne `wc -c <'flex.1'`; then
  814.     echo shar: \"'flex.1'\" unpacked with wrong size!
  815. fi
  816. # end of 'flex.1'
  817. fi
  818. if test -f 'tblcmp.c' -a "${1}" != "-c" ; then 
  819.   echo shar: Will not clobber existing file \"'tblcmp.c'\"
  820. else
  821. echo shar: Extracting \"'tblcmp.c'\" \(25169 characters\)
  822. sed "s/^X//" >'tblcmp.c' <<'END_OF_FILE'
  823. X/* tblcmp - table compression routines */
  824. X
  825. X/*-
  826. X * Copyright (c) 1990 The Regents of the University of California.
  827. X * All rights reserved.
  828. X *
  829. X * This code is derived from software contributed to Berkeley by
  830. X * Vern Paxson.
  831. X * 
  832. X * The United States Government has rights in this work pursuant
  833. X * to contract no. DE-AC03-76SF00098 between the United States
  834. X * Department of Energy and the University of California.
  835. X *
  836. X * Redistribution and use in source and binary forms are permitted provided
  837. X * that: (1) source distributions retain this entire copyright notice and
  838. X * comment, and (2) distributions including binaries display the following
  839. X * acknowledgement:  ``This product includes software developed by the
  840. X * University of California, Berkeley and its contributors'' in the
  841. X * documentation or other materials provided with the distribution and in
  842. X * all advertising materials mentioning features or use of this software.
  843. X * Neither the name of the University nor the names of its contributors may
  844. X * be used to endorse or promote products derived from this software without
  845. X * specific prior written permission.
  846. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  847. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  848. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  849. X */
  850. X
  851. X#ifndef lint
  852. Xstatic char rcsid[] =
  853. X    "@(#) $Header: /usr/fsys/odin/a/vern/flex/RCS/tblcmp.c,v 2.5 90/06/27 23:48:38 vern Exp $ (LBL)";
  854. X#endif
  855. X
  856. X#include "flexdef.h"
  857. X
  858. X
  859. X/* declarations for functions that have forward references */
  860. X
  861. Xvoid mkentry PROTO((register int*, int, int, int, int));
  862. Xvoid mkprot PROTO((int[], int, int));
  863. Xvoid mktemplate PROTO((int[], int, int));
  864. Xvoid mv2front PROTO((int));
  865. Xint tbldiff PROTO((int[], int, int[]));
  866. X
  867. X
  868. X/* bldtbl - build table entries for dfa state
  869. X *
  870. X * synopsis
  871. X *   int state[numecs], statenum, totaltrans, comstate, comfreq;
  872. X *   bldtbl( state, statenum, totaltrans, comstate, comfreq );
  873. X *
  874. X * State is the statenum'th dfa state.  It is indexed by equivalence class and
  875. X * gives the number of the state to enter for a given equivalence class.
  876. X * totaltrans is the total number of transitions out of the state.  Comstate
  877. X * is that state which is the destination of the most transitions out of State.
  878. X * Comfreq is how many transitions there are out of State to Comstate.
  879. X *
  880. X * A note on terminology:
  881. X *    "protos" are transition tables which have a high probability of
  882. X * either being redundant (a state processed later will have an identical
  883. X * transition table) or nearly redundant (a state processed later will have
  884. X * many of the same out-transitions).  A "most recently used" queue of
  885. X * protos is kept around with the hope that most states will find a proto
  886. X * which is similar enough to be usable, and therefore compacting the
  887. X * output tables.
  888. X *    "templates" are a special type of proto.  If a transition table is
  889. X * homogeneous or nearly homogeneous (all transitions go to the same
  890. X * destination) then the odds are good that future states will also go
  891. X * to the same destination state on basically the same character set.
  892. X * These homogeneous states are so common when dealing with large rule
  893. X * sets that they merit special attention.  If the transition table were
  894. X * simply made into a proto, then (typically) each subsequent, similar
  895. X * state will differ from the proto for two out-transitions.  One of these
  896. X * out-transitions will be that character on which the proto does not go
  897. X * to the common destination, and one will be that character on which the
  898. X * state does not go to the common destination.  Templates, on the other
  899. X * hand, go to the common state on EVERY transition character, and therefore
  900. X * cost only one difference.
  901. X */
  902. X
  903. Xvoid bldtbl( state, statenum, totaltrans, comstate, comfreq )
  904. Xint state[], statenum, totaltrans, comstate, comfreq;
  905. X
  906. X    {
  907. X    int extptr, extrct[2][CSIZE + 1];
  908. X    int mindiff, minprot, i, d;
  909. X    int checkcom;
  910. X
  911. X    /* If extptr is 0 then the first array of extrct holds the result of the
  912. X     * "best difference" to date, which is those transitions which occur in
  913. X     * "state" but not in the proto which, to date, has the fewest differences
  914. X     * between itself and "state".  If extptr is 1 then the second array of
  915. X     * extrct hold the best difference.  The two arrays are toggled
  916. X     * between so that the best difference to date can be kept around and
  917. X     * also a difference just created by checking against a candidate "best"
  918. X     * proto.
  919. X     */
  920. X
  921. X    extptr = 0;
  922. X
  923. X    /* if the state has too few out-transitions, don't bother trying to
  924. X     * compact its tables
  925. X     */
  926. X
  927. X    if ( (totaltrans * 100) < (numecs * PROTO_SIZE_PERCENTAGE) )
  928. X    mkentry( state, numecs, statenum, JAMSTATE, totaltrans );
  929. X
  930. X    else
  931. X    {
  932. X    /* checkcom is true if we should only check "state" against
  933. X     * protos which have the same "comstate" value
  934. X     */
  935. X
  936. X    checkcom = comfreq * 100 > totaltrans * CHECK_COM_PERCENTAGE;
  937. X
  938. X    minprot = firstprot;
  939. X    mindiff = totaltrans;
  940. X
  941. X    if ( checkcom )
  942. X        {
  943. X        /* find first proto which has the same "comstate" */
  944. X        for ( i = firstprot; i != NIL; i = protnext[i] )
  945. X        if ( protcomst[i] == comstate )
  946. X            {
  947. X            minprot = i;
  948. X            mindiff = tbldiff( state, minprot, extrct[extptr] );
  949. X            break;
  950. X            }
  951. X        }
  952. X
  953. X    else
  954. X        {
  955. X        /* since we've decided that the most common destination out
  956. X         * of "state" does not occur with a high enough frequency,
  957. X         * we set the "comstate" to zero, assuring that if this state
  958. X         * is entered into the proto list, it will not be considered
  959. X         * a template.
  960. X         */
  961. X        comstate = 0;
  962. X
  963. X        if ( firstprot != NIL )
  964. X        {
  965. X        minprot = firstprot;
  966. X        mindiff = tbldiff( state, minprot, extrct[extptr] );
  967. X        }
  968. X        }
  969. X
  970. X    /* we now have the first interesting proto in "minprot".  If
  971. X     * it matches within the tolerances set for the first proto,
  972. X     * we don't want to bother scanning the rest of the proto list
  973. X     * to see if we have any other reasonable matches.
  974. X     */
  975. X
  976. X    if ( mindiff * 100 > totaltrans * FIRST_MATCH_DIFF_PERCENTAGE )
  977. X        { /* not a good enough match.  Scan the rest of the protos */
  978. X        for ( i = minprot; i != NIL; i = protnext[i] )
  979. X        {
  980. X        d = tbldiff( state, i, extrct[1 - extptr] );
  981. X        if ( d < mindiff )
  982. X            {
  983. X            extptr = 1 - extptr;
  984. X            mindiff = d;
  985. X            minprot = i;
  986. X            }
  987. X        }
  988. X        }
  989. X
  990. X    /* check if the proto we've decided on as our best bet is close
  991. X     * enough to the state we want to match to be usable
  992. X     */
  993. X
  994. X    if ( mindiff * 100 > totaltrans * ACCEPTABLE_DIFF_PERCENTAGE )
  995. X        {
  996. X        /* no good.  If the state is homogeneous enough, we make a
  997. X         * template out of it.  Otherwise, we make a proto.
  998. X         */
  999. X
  1000. X        if ( comfreq * 100 >= totaltrans * TEMPLATE_SAME_PERCENTAGE )
  1001. X        mktemplate( state, statenum, comstate );
  1002. X
  1003. X        else
  1004. X        {
  1005. X        mkprot( state, statenum, comstate );
  1006. X        mkentry( state, numecs, statenum, JAMSTATE, totaltrans );
  1007. X        }
  1008. X        }
  1009. X
  1010. X    else
  1011. X        { /* use the proto */
  1012. X        mkentry( extrct[extptr], numecs, statenum,
  1013. X             prottbl[minprot], mindiff );
  1014. X
  1015. X        /* if this state was sufficiently different from the proto
  1016. X         * we built it from, make it, too, a proto
  1017. X         */
  1018. X
  1019. X        if ( mindiff * 100 >= totaltrans * NEW_PROTO_DIFF_PERCENTAGE )
  1020. X        mkprot( state, statenum, comstate );
  1021. X
  1022. X        /* since mkprot added a new proto to the proto queue, it's possible
  1023. X         * that "minprot" is no longer on the proto queue (if it happened
  1024. X         * to have been the last entry, it would have been bumped off).
  1025. X         * If it's not there, then the new proto took its physical place
  1026. X         * (though logically the new proto is at the beginning of the
  1027. X         * queue), so in that case the following call will do nothing.
  1028. X         */
  1029. X
  1030. X        mv2front( minprot );
  1031. X        }
  1032. X    }
  1033. X    }
  1034. X
  1035. X
  1036. X/* cmptmps - compress template table entries
  1037. X *
  1038. X * synopsis
  1039. X *    cmptmps();
  1040. X *
  1041. X *  template tables are compressed by using the 'template equivalence
  1042. X *  classes', which are collections of transition character equivalence
  1043. X *  classes which always appear together in templates - really meta-equivalence
  1044. X *  classes.  until this point, the tables for templates have been stored
  1045. X *  up at the top end of the nxt array; they will now be compressed and have
  1046. X *  table entries made for them.
  1047. X */
  1048. X
  1049. Xvoid cmptmps()
  1050. X
  1051. X    {
  1052. X    int tmpstorage[CSIZE + 1];
  1053. X    register int *tmp = tmpstorage, i, j;
  1054. X    int totaltrans, trans;
  1055. X
  1056. X    peakpairs = numtemps * numecs + tblend;
  1057. X
  1058. X    if ( usemecs )
  1059. X    {
  1060. X    /* create equivalence classes base on data gathered on template
  1061. X     * transitions
  1062. X     */
  1063. X
  1064. X    nummecs = cre8ecs( tecfwd, tecbck, numecs );
  1065. X    }
  1066. X    
  1067. X    else
  1068. X    nummecs = numecs;
  1069. X
  1070. X    if ( lastdfa + numtemps + 1 >= current_max_dfas )
  1071. X    increase_max_dfas();
  1072. X
  1073. X    /* loop through each template */
  1074. X
  1075. X    for ( i = 1; i <= numtemps; ++i )
  1076. X    {
  1077. X    totaltrans = 0;    /* number of non-jam transitions out of this template */
  1078. X
  1079. X    for ( j = 1; j <= numecs; ++j )
  1080. X        {
  1081. X        trans = tnxt[numecs * i + j];
  1082. X
  1083. X        if ( usemecs )
  1084. X        {
  1085. X        /* the absolute value of tecbck is the meta-equivalence class
  1086. X         * of a given equivalence class, as set up by cre8ecs
  1087. X         */
  1088. X        if ( tecbck[j] > 0 )
  1089. X            {
  1090. X            tmp[tecbck[j]] = trans;
  1091. X
  1092. X            if ( trans > 0 )
  1093. X            ++totaltrans;
  1094. X            }
  1095. X        }
  1096. X
  1097. X        else
  1098. X        {
  1099. X        tmp[j] = trans;
  1100. X
  1101. X        if ( trans > 0 )
  1102. X            ++totaltrans;
  1103. X        }
  1104. X        }
  1105. X
  1106. X    /* it is assumed (in a rather subtle way) in the skeleton that
  1107. X     * if we're using meta-equivalence classes, the def[] entry for
  1108. X     * all templates is the jam template, i.e., templates never default
  1109. X     * to other non-jam table entries (e.g., another template)
  1110. X     */
  1111. X
  1112. X    /* leave room for the jam-state after the last real state */
  1113. X    mkentry( tmp, nummecs, lastdfa + i + 1, JAMSTATE, totaltrans );
  1114. X    }
  1115. X    }
  1116. X
  1117. X
  1118. X
  1119. X/* expand_nxt_chk - expand the next check arrays */
  1120. X
  1121. Xvoid expand_nxt_chk()
  1122. X
  1123. X    {
  1124. X    register int old_max = current_max_xpairs;
  1125. X
  1126. X    current_max_xpairs += MAX_XPAIRS_INCREMENT;
  1127. X
  1128. X    ++num_reallocs;
  1129. X
  1130. X    nxt = reallocate_integer_array( nxt, current_max_xpairs );
  1131. X    chk = reallocate_integer_array( chk, current_max_xpairs );
  1132. X
  1133. X    bzero( (char *) (chk + old_max),
  1134. X       MAX_XPAIRS_INCREMENT * sizeof( int ) / sizeof( char ) );
  1135. X    }
  1136. X
  1137. X
  1138. X/* find_table_space - finds a space in the table for a state to be placed
  1139. X *
  1140. X * synopsis
  1141. X *     int *state, numtrans, block_start;
  1142. X *     int find_table_space();
  1143. X *
  1144. X *     block_start = find_table_space( state, numtrans );
  1145. X *
  1146. X * State is the state to be added to the full speed transition table.
  1147. X * Numtrans is the number of out-transitions for the state.
  1148. X *
  1149. X * find_table_space() returns the position of the start of the first block (in
  1150. X * chk) able to accommodate the state
  1151. X *
  1152. X * In determining if a state will or will not fit, find_table_space() must take
  1153. X * into account the fact that an end-of-buffer state will be added at [0],
  1154. X * and an action number will be added in [-1].
  1155. X */
  1156. X
  1157. Xint find_table_space( state, numtrans )
  1158. Xint *state, numtrans;
  1159. X    
  1160. X    {
  1161. X    /* firstfree is the position of the first possible occurrence of two
  1162. X     * consecutive unused records in the chk and nxt arrays
  1163. X     */
  1164. X    register int i;
  1165. X    register int *state_ptr, *chk_ptr;
  1166. X    register int *ptr_to_last_entry_in_state;
  1167. X
  1168. X    /* if there are too many out-transitions, put the state at the end of
  1169. X     * nxt and chk
  1170. X     */
  1171. X    if ( numtrans > MAX_XTIONS_FULL_INTERIOR_FIT )
  1172. X    {
  1173. X    /* if table is empty, return the first available spot in chk/nxt,
  1174. X     * which should be 1
  1175. X     */
  1176. X    if ( tblend < 2 )
  1177. X        return ( 1 );
  1178. X
  1179. X    i = tblend - numecs;    /* start searching for table space near the
  1180. X                 * end of chk/nxt arrays
  1181. X                 */
  1182. X    }
  1183. X
  1184. X    else
  1185. X    i = firstfree;        /* start searching for table space from the
  1186. X                 * beginning (skipping only the elements
  1187. X                 * which will definitely not hold the new
  1188. X                 * state)
  1189. X                 */
  1190. X
  1191. X    while ( 1 )        /* loops until a space is found */
  1192. X    {
  1193. X    if ( i + numecs > current_max_xpairs )
  1194. X        expand_nxt_chk();
  1195. X
  1196. X    /* loops until space for end-of-buffer and action number are found */
  1197. X    while ( 1 )
  1198. X        {
  1199. X        if ( chk[i - 1] == 0 )    /* check for action number space */
  1200. X        {
  1201. X        if ( chk[i] == 0 )    /* check for end-of-buffer space */
  1202. X            break;
  1203. X
  1204. X        else
  1205. X            i += 2;    /* since i != 0, there is no use checking to
  1206. X                 * see if (++i) - 1 == 0, because that's the
  1207. X                 * same as i == 0, so we skip a space
  1208. X                 */
  1209. X        }
  1210. X
  1211. X        else
  1212. X        ++i;
  1213. X
  1214. X        if ( i + numecs > current_max_xpairs )
  1215. X        expand_nxt_chk();
  1216. X        }
  1217. X
  1218. X    /* if we started search from the beginning, store the new firstfree for
  1219. X     * the next call of find_table_space()
  1220. X     */
  1221. X    if ( numtrans <= MAX_XTIONS_FULL_INTERIOR_FIT )
  1222. X        firstfree = i + 1;
  1223. X
  1224. X    /* check to see if all elements in chk (and therefore nxt) that are
  1225. X     * needed for the new state have not yet been taken
  1226. X     */
  1227. X
  1228. X    state_ptr = &state[1];
  1229. X    ptr_to_last_entry_in_state = &chk[i + numecs + 1];
  1230. X
  1231. X    for ( chk_ptr = &chk[i + 1]; chk_ptr != ptr_to_last_entry_in_state;
  1232. X          ++chk_ptr )
  1233. X        if ( *(state_ptr++) != 0 && *chk_ptr != 0 )
  1234. X        break;
  1235. X
  1236. X    if ( chk_ptr == ptr_to_last_entry_in_state )
  1237. X        return ( i );
  1238. X
  1239. X    else
  1240. X        ++i;
  1241. X    }
  1242. X    }
  1243. X
  1244. X
  1245. X/* inittbl - initialize transition tables
  1246. X *
  1247. X * synopsis
  1248. X *   inittbl();
  1249. X *
  1250. X * Initializes "firstfree" to be one beyond the end of the table.  Initializes
  1251. X * all "chk" entries to be zero.  Note that templates are built in their
  1252. X * own tbase/tdef tables.  They are shifted down to be contiguous
  1253. X * with the non-template entries during table generation.
  1254. X */
  1255. Xvoid inittbl()
  1256. X
  1257. X    {
  1258. X    register int i;
  1259. X
  1260. X    bzero( (char *) chk, current_max_xpairs * sizeof( int ) / sizeof( char ) );
  1261. X
  1262. X    tblend = 0;
  1263. X    firstfree = tblend + 1;
  1264. X    numtemps = 0;
  1265. X
  1266. X    if ( usemecs )
  1267. X    {
  1268. X    /* set up doubly-linked meta-equivalence classes
  1269. X     * these are sets of equivalence classes which all have identical
  1270. X     * transitions out of TEMPLATES
  1271. X     */
  1272. X
  1273. X    tecbck[1] = NIL;
  1274. X
  1275. X    for ( i = 2; i <= numecs; ++i )
  1276. X        {
  1277. X        tecbck[i] = i - 1;
  1278. X        tecfwd[i - 1] = i;
  1279. X        }
  1280. X
  1281. X    tecfwd[numecs] = NIL;
  1282. X    }
  1283. X    }
  1284. X
  1285. X
  1286. X/* mkdeftbl - make the default, "jam" table entries
  1287. X *
  1288. X * synopsis
  1289. X *   mkdeftbl();
  1290. X */
  1291. X
  1292. Xvoid mkdeftbl()
  1293. X
  1294. X    {
  1295. X    int i;
  1296. X
  1297. X    jamstate = lastdfa + 1;
  1298. X
  1299. X    ++tblend; /* room for transition on end-of-buffer character */
  1300. X
  1301. X    if ( tblend + numecs > current_max_xpairs )
  1302. X    expand_nxt_chk();
  1303. X
  1304. X    /* add in default end-of-buffer transition */
  1305. X    nxt[tblend] = end_of_buffer_state;
  1306. X    chk[tblend] = jamstate;
  1307. X
  1308. X    for ( i = 1; i <= numecs; ++i )
  1309. X    {
  1310. X    nxt[tblend + i] = 0;
  1311. X    chk[tblend + i] = jamstate;
  1312. X    }
  1313. X
  1314. X    jambase = tblend;
  1315. X
  1316. X    base[jamstate] = jambase;
  1317. X    def[jamstate] = 0;
  1318. X
  1319. X    tblend += numecs;
  1320. X    ++numtemps;
  1321. X    }
  1322. X
  1323. X
  1324. X/* mkentry - create base/def and nxt/chk entries for transition array
  1325. X *
  1326. X * synopsis
  1327. X *   int state[numchars + 1], numchars, statenum, deflink, totaltrans;
  1328. X *   mkentry( state, numchars, statenum, deflink, totaltrans );
  1329. X *
  1330. X * "state" is a transition array "numchars" characters in size, "statenum"
  1331. X * is the offset to be used into the base/def tables, and "deflink" is the
  1332. X * entry to put in the "def" table entry.  If "deflink" is equal to
  1333. X * "JAMSTATE", then no attempt will be made to fit zero entries of "state"
  1334. X * (i.e., jam entries) into the table.  It is assumed that by linking to
  1335. X * "JAMSTATE" they will be taken care of.  In any case, entries in "state"
  1336. X * marking transitions to "SAME_TRANS" are treated as though they will be
  1337. X * taken care of by whereever "deflink" points.  "totaltrans" is the total
  1338. X * number of transitions out of the state.  If it is below a certain threshold,
  1339. X * the tables are searched for an interior spot that will accommodate the
  1340. X * state array.
  1341. X */
  1342. X
  1343. Xvoid mkentry( state, numchars, statenum, deflink, totaltrans )
  1344. Xregister int *state;
  1345. Xint numchars, statenum, deflink, totaltrans;
  1346. X
  1347. X    {
  1348. X    register int minec, maxec, i, baseaddr;
  1349. X    int tblbase, tbllast;
  1350. X
  1351. X    if ( totaltrans == 0 )
  1352. X    { /* there are no out-transitions */
  1353. X    if ( deflink == JAMSTATE )
  1354. X        base[statenum] = JAMSTATE;
  1355. X    else
  1356. X        base[statenum] = 0;
  1357. X
  1358. X    def[statenum] = deflink;
  1359. X    return;
  1360. X    }
  1361. X
  1362. X    for ( minec = 1; minec <= numchars; ++minec )
  1363. X    {
  1364. X    if ( state[minec] != SAME_TRANS )
  1365. X        if ( state[minec] != 0 || deflink != JAMSTATE )
  1366. X        break;
  1367. X    }
  1368. X
  1369. X    if ( totaltrans == 1 )
  1370. X    {
  1371. X    /* there's only one out-transition.  Save it for later to fill
  1372. X     * in holes in the tables.
  1373. X     */
  1374. X    stack1( statenum, minec, state[minec], deflink );
  1375. X    return;
  1376. X    }
  1377. X
  1378. X    for ( maxec = numchars; maxec > 0; --maxec )
  1379. X    {
  1380. X    if ( state[maxec] != SAME_TRANS )
  1381. X        if ( state[maxec] != 0 || deflink != JAMSTATE )
  1382. X        break;
  1383. X    }
  1384. X
  1385. X    /* Whether we try to fit the state table in the middle of the table
  1386. X     * entries we have already generated, or if we just take the state
  1387. X     * table at the end of the nxt/chk tables, we must make sure that we
  1388. X     * have a valid base address (i.e., non-negative).  Note that not only are
  1389. X     * negative base addresses dangerous at run-time (because indexing the
  1390. X     * next array with one and a low-valued character might generate an
  1391. X     * array-out-of-bounds error message), but at compile-time negative
  1392. X     * base addresses denote TEMPLATES.
  1393. X     */
  1394. X
  1395. X    /* find the first transition of state that we need to worry about. */
  1396. X    if ( totaltrans * 100 <= numchars * INTERIOR_FIT_PERCENTAGE )
  1397. X    { /* attempt to squeeze it into the middle of the tabls */
  1398. X    baseaddr = firstfree;
  1399. X
  1400. X    while ( baseaddr < minec )
  1401. X        {
  1402. X        /* using baseaddr would result in a negative base address below
  1403. X         * find the next free slot
  1404. X         */
  1405. X        for ( ++baseaddr; chk[baseaddr] != 0; ++baseaddr )
  1406. X        ;
  1407. X        }
  1408. X
  1409. X    if ( baseaddr + maxec - minec >= current_max_xpairs )
  1410. X        expand_nxt_chk();
  1411. X
  1412. X    for ( i = minec; i <= maxec; ++i )
  1413. X        if ( state[i] != SAME_TRANS )
  1414. X        if ( state[i] != 0 || deflink != JAMSTATE )
  1415. X            if ( chk[baseaddr + i - minec] != 0 )
  1416. X            { /* baseaddr unsuitable - find another */
  1417. X            for ( ++baseaddr;
  1418. X                  baseaddr < current_max_xpairs &&
  1419. X                  chk[baseaddr] != 0;
  1420. X                  ++baseaddr )
  1421. X                ;
  1422. X
  1423. X            if ( baseaddr + maxec - minec >= current_max_xpairs )
  1424. X                expand_nxt_chk();
  1425. X
  1426. X            /* reset the loop counter so we'll start all
  1427. X             * over again next time it's incremented
  1428. X             */
  1429. X
  1430. X            i = minec - 1;
  1431. X            }
  1432. X    }
  1433. X
  1434. X    else
  1435. X    {
  1436. X    /* ensure that the base address we eventually generate is
  1437. X     * non-negative
  1438. X     */
  1439. X    baseaddr = max( tblend + 1, minec );
  1440. X    }
  1441. X
  1442. X    tblbase = baseaddr - minec;
  1443. X    tbllast = tblbase + maxec;
  1444. X
  1445. X    if ( tbllast >= current_max_xpairs )
  1446. X    expand_nxt_chk();
  1447. X
  1448. X    base[statenum] = tblbase;
  1449. X    def[statenum] = deflink;
  1450. X
  1451. X    for ( i = minec; i <= maxec; ++i )
  1452. X    if ( state[i] != SAME_TRANS )
  1453. X        if ( state[i] != 0 || deflink != JAMSTATE )
  1454. X        {
  1455. X        nxt[tblbase + i] = state[i];
  1456. X        chk[tblbase + i] = statenum;
  1457. X        }
  1458. X
  1459. X    if ( baseaddr == firstfree )
  1460. X    /* find next free slot in tables */
  1461. X    for ( ++firstfree; chk[firstfree] != 0; ++firstfree )
  1462. X        ;
  1463. X
  1464. X    tblend = max( tblend, tbllast );
  1465. X    }
  1466. X
  1467. X
  1468. X/* mk1tbl - create table entries for a state (or state fragment) which
  1469. X *            has only one out-transition
  1470. X *
  1471. X * synopsis
  1472. X *   int state, sym, onenxt, onedef;
  1473. X *   mk1tbl( state, sym, onenxt, onedef );
  1474. X */
  1475. X
  1476. Xvoid mk1tbl( state, sym, onenxt, onedef )
  1477. Xint state, sym, onenxt, onedef;
  1478. X
  1479. X    {
  1480. X    if ( firstfree < sym )
  1481. X    firstfree = sym;
  1482. X
  1483. X    while ( chk[firstfree] != 0 )
  1484. X    if ( ++firstfree >= current_max_xpairs )
  1485. X        expand_nxt_chk();
  1486. X
  1487. X    base[state] = firstfree - sym;
  1488. X    def[state] = onedef;
  1489. X    chk[firstfree] = state;
  1490. X    nxt[firstfree] = onenxt;
  1491. X
  1492. X    if ( firstfree > tblend )
  1493. X    {
  1494. X    tblend = firstfree++;
  1495. X
  1496. X    if ( firstfree >= current_max_xpairs )
  1497. X        expand_nxt_chk();
  1498. X    }
  1499. X    }
  1500. X
  1501. X
  1502. X/* mkprot - create new proto entry
  1503. X *
  1504. X * synopsis
  1505. X *   int state[], statenum, comstate;
  1506. X *   mkprot( state, statenum, comstate );
  1507. X */
  1508. X
  1509. Xvoid mkprot( state, statenum, comstate )
  1510. Xint state[], statenum, comstate;
  1511. X
  1512. X    {
  1513. X    int i, slot, tblbase;
  1514. X
  1515. X    if ( ++numprots >= MSP || numecs * numprots >= PROT_SAVE_SIZE )
  1516. X    {
  1517. X    /* gotta make room for the new proto by dropping last entry in
  1518. X     * the queue
  1519. X     */
  1520. X    slot = lastprot;
  1521. X    lastprot = protprev[lastprot];
  1522. X    protnext[lastprot] = NIL;
  1523. X    }
  1524. X
  1525. X    else
  1526. X    slot = numprots;
  1527. X
  1528. X    protnext[slot] = firstprot;
  1529. X
  1530. X    if ( firstprot != NIL )
  1531. X    protprev[firstprot] = slot;
  1532. X
  1533. X    firstprot = slot;
  1534. X    prottbl[slot] = statenum;
  1535. X    protcomst[slot] = comstate;
  1536. X
  1537. X    /* copy state into save area so it can be compared with rapidly */
  1538. X    tblbase = numecs * (slot - 1);
  1539. X
  1540. X    for ( i = 1; i <= numecs; ++i )
  1541. X    protsave[tblbase + i] = state[i];
  1542. X    }
  1543. X
  1544. X
  1545. X/* mktemplate - create a template entry based on a state, and connect the state
  1546. X *              to it
  1547. X *
  1548. X * synopsis
  1549. X *   int state[], statenum, comstate, totaltrans;
  1550. X *   mktemplate( state, statenum, comstate, totaltrans );
  1551. X */
  1552. X
  1553. Xvoid mktemplate( state, statenum, comstate )
  1554. Xint state[], statenum, comstate;
  1555. X
  1556. X    {
  1557. X    int i, numdiff, tmpbase, tmp[CSIZE + 1];
  1558. X    Char transset[CSIZE + 1];
  1559. X    int tsptr;
  1560. X
  1561. X    ++numtemps;
  1562. X
  1563. X    tsptr = 0;
  1564. X
  1565. X    /* calculate where we will temporarily store the transition table
  1566. X     * of the template in the tnxt[] array.  The final transition table
  1567. X     * gets created by cmptmps()
  1568. X     */
  1569. X
  1570. X    tmpbase = numtemps * numecs;
  1571. X
  1572. X    if ( tmpbase + numecs >= current_max_template_xpairs )
  1573. X    {
  1574. X    current_max_template_xpairs += MAX_TEMPLATE_XPAIRS_INCREMENT;
  1575. X
  1576. X    ++num_reallocs;
  1577. X
  1578. X    tnxt = reallocate_integer_array( tnxt, current_max_template_xpairs );
  1579. X    }
  1580. X
  1581. X    for ( i = 1; i <= numecs; ++i )
  1582. X    if ( state[i] == 0 )
  1583. X        tnxt[tmpbase + i] = 0;
  1584. X    else
  1585. X        {
  1586. X        transset[tsptr++] = i;
  1587. X        tnxt[tmpbase + i] = comstate;
  1588. X        }
  1589. X
  1590. X    if ( usemecs )
  1591. X    mkeccl( transset, tsptr, tecfwd, tecbck, numecs, 0 );
  1592. X
  1593. X    mkprot( tnxt + tmpbase, -numtemps, comstate );
  1594. X
  1595. X    /* we rely on the fact that mkprot adds things to the beginning
  1596. X     * of the proto queue
  1597. X     */
  1598. X
  1599. X    numdiff = tbldiff( state, firstprot, tmp );
  1600. X    mkentry( tmp, numecs, statenum, -numtemps, numdiff );
  1601. X    }
  1602. X
  1603. X
  1604. X/* mv2front - move proto queue element to front of queue
  1605. X *
  1606. X * synopsis
  1607. X *   int qelm;
  1608. X *   mv2front( qelm );
  1609. X */
  1610. X
  1611. Xvoid mv2front( qelm )
  1612. Xint qelm;
  1613. X
  1614. X    {
  1615. X    if ( firstprot != qelm )
  1616. X    {
  1617. X    if ( qelm == lastprot )
  1618. X        lastprot = protprev[lastprot];
  1619. X
  1620. X    protnext[protprev[qelm]] = protnext[qelm];
  1621. X
  1622. X    if ( protnext[qelm] != NIL )
  1623. X        protprev[protnext[qelm]] = protprev[qelm];
  1624. X
  1625. X    protprev[qelm] = NIL;
  1626. X    protnext[qelm] = firstprot;
  1627. X    protprev[firstprot] = qelm;
  1628. X    firstprot = qelm;
  1629. X    }
  1630. X    }
  1631. X
  1632. X
  1633. X/* place_state - place a state into full speed transition table
  1634. X *
  1635. X * synopsis
  1636. X *     int *state, statenum, transnum;
  1637. X *     place_state( state, statenum, transnum );
  1638. X *
  1639. X * State is the statenum'th state.  It is indexed by equivalence class and
  1640. X * gives the number of the state to enter for a given equivalence class.
  1641. X * Transnum is the number of out-transitions for the state.
  1642. X */
  1643. X
  1644. Xvoid place_state( state, statenum, transnum )
  1645. Xint *state, statenum, transnum;
  1646. X
  1647. X    {
  1648. X    register int i;
  1649. X    register int *state_ptr;
  1650. X    int position = find_table_space( state, transnum );
  1651. X
  1652. X    /* base is the table of start positions */
  1653. X    base[statenum] = position;
  1654. X
  1655. X    /* put in action number marker; this non-zero number makes sure that
  1656. X     * find_table_space() knows that this position in chk/nxt is taken
  1657. X     * and should not be used for another accepting number in another state
  1658. X     */
  1659. X    chk[position - 1] = 1;
  1660. X
  1661. X    /* put in end-of-buffer marker; this is for the same purposes as above */
  1662. X    chk[position] = 1;
  1663. X
  1664. X    /* place the state into chk and nxt */
  1665. X    state_ptr = &state[1];
  1666. X
  1667. X    for ( i = 1; i <= numecs; ++i, ++state_ptr )
  1668. X    if ( *state_ptr != 0 )
  1669. X        {
  1670. X        chk[position + i] = i;
  1671. X        nxt[position + i] = *state_ptr;
  1672. X        }
  1673. X
  1674. X    if ( position + numecs > tblend )
  1675. X    tblend = position + numecs;
  1676. X    }
  1677. X
  1678. X
  1679. X/* stack1 - save states with only one out-transition to be processed later
  1680. X *
  1681. X * synopsis
  1682. X *   int statenum, sym, nextstate, deflink;
  1683. X *   stack1( statenum, sym, nextstate, deflink );
  1684. X *
  1685. X * if there's room for another state one the "one-transition" stack, the
  1686. X * state is pushed onto it, to be processed later by mk1tbl.  If there's
  1687. X * no room, we process the sucker right now.
  1688. X */
  1689. X
  1690. Xvoid stack1( statenum, sym, nextstate, deflink )
  1691. Xint statenum, sym, nextstate, deflink;
  1692. X
  1693. X    {
  1694. X    if ( onesp >= ONE_STACK_SIZE - 1 )
  1695. X    mk1tbl( statenum, sym, nextstate, deflink );
  1696. X
  1697. X    else
  1698. X    {
  1699. X    ++onesp;
  1700. X    onestate[onesp] = statenum;
  1701. X    onesym[onesp] = sym;
  1702. X    onenext[onesp] = nextstate;
  1703. X    onedef[onesp] = deflink;
  1704. X    }
  1705. X    }
  1706. X
  1707. X
  1708. X/* tbldiff - compute differences between two state tables
  1709. X *
  1710. X * synopsis
  1711. X *   int state[], pr, ext[];
  1712. X *   int tbldiff, numdifferences;
  1713. X *   numdifferences = tbldiff( state, pr, ext )
  1714. X *
  1715. X * "state" is the state array which is to be extracted from the pr'th
  1716. X * proto.  "pr" is both the number of the proto we are extracting from
  1717. X * and an index into the save area where we can find the proto's complete
  1718. X * state table.  Each entry in "state" which differs from the corresponding
  1719. X * entry of "pr" will appear in "ext".
  1720. X * Entries which are the same in both "state" and "pr" will be marked
  1721. X * as transitions to "SAME_TRANS" in "ext".  The total number of differences
  1722. X * between "state" and "pr" is returned as function value.  Note that this
  1723. X * number is "numecs" minus the number of "SAME_TRANS" entries in "ext".
  1724. X */
  1725. X
  1726. Xint tbldiff( state, pr, ext )
  1727. Xint state[], pr, ext[];
  1728. X
  1729. X    {
  1730. X    register int i, *sp = state, *ep = ext, *protp;
  1731. X    register int numdiff = 0;
  1732. X
  1733. X    protp = &protsave[numecs * (pr - 1)];
  1734. X
  1735. X    for ( i = numecs; i > 0; --i )
  1736. X    {
  1737. X    if ( *++protp == *++sp )
  1738. X        *++ep = SAME_TRANS;
  1739. X    else
  1740. X        {
  1741. X        *++ep = *sp;
  1742. X        ++numdiff;
  1743. X        }
  1744. X    }
  1745. X
  1746. X    return ( numdiff );
  1747. X    }
  1748. END_OF_FILE
  1749. if test 25169 -ne `wc -c <'tblcmp.c'`; then
  1750.     echo shar: \"'tblcmp.c'\" unpacked with wrong size!
  1751. fi
  1752. # end of 'tblcmp.c'
  1753. fi
  1754. echo shar: End of archive 4 \(of 13\).
  1755. cp /dev/null ark4isdone
  1756. MISSING=""
  1757. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  1758.     if test ! -f ark${I}isdone ; then
  1759.     MISSING="${MISSING} ${I}"
  1760.     fi
  1761. done
  1762. if test "${MISSING}" = "" ; then
  1763.     echo You have unpacked all 13 archives.
  1764.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1765. else
  1766.     echo You still need to unpack the following archives:
  1767.     echo "        " ${MISSING}
  1768. fi
  1769. ##  End of shell archive.
  1770. exit 0
  1771. -- 
  1772. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  1773. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  1774. Post requests for sources, and general discussion to comp.sys.amiga.
  1775.